package org.neuedu.controller;

import ch.qos.logback.core.net.SyslogOutputStream;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.neuedu.api.AdminService;
import org.neuedu.common.ResultCode;
import org.neuedu.common.ResultJson;
import org.neuedu.entity.Register;
import org.neuedu.entity.SettleCategory;
import org.neuedu.query.EmpCountQuota;
import org.neuedu.service.RegisterService;
import org.neuedu.service.SettleCategoryService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lzw
 * @since 2024-11-11
 */
@RestController
@RequestMapping("/register")
public class RegisterController {
    @Resource
    SettleCategoryService settleCategoryService;
    @Resource
    AdminService adminService;
    @Resource
    RegisterService registerService;

    @GetMapping("/list")
    ResultJson<IPage<Register>> list(Integer pageNo,Integer pageSize,String caseNumber,String realName,Long openId,Integer visitState){
        return ResultJson.success(registerService.list(pageNo,pageSize, caseNumber, realName,openId,visitState)) ;
    }
    @GetMapping("/getRegisterData")
    public ResultJson<HashMap<String,List<?>>> getRegisterData(){
        HashMap<String,List<?>> hashMap=new HashMap<>();
        hashMap.put("depts",adminService.getRegisterDept());
        hashMap.put("levels",adminService.getRegistLevelActive());
        hashMap.put("settles",settleCategoryService.getActive());
        return ResultJson.success(hashMap);
    }

    @GetMapping("/getRegisterCount")
    ResultJson<Integer> getRegisterCount(LocalDate visitDate, Long employeeId, String noon) {
        return ResultJson.success(registerService.getRegisterCount(visitDate,employeeId,noon));
    }

    @PostMapping("/saveRegister")
    public ResultJson<String> saveRegister(Register register){
        return ResultJson.success(registerService.add(register));
    }
    @RequestMapping ("/updatePay")
    String updatePay(HttpServletRequest request){
        return registerService.updatePay(request);
    }
    @GetMapping("/call")
    ResultJson<Boolean> call(Integer num,String realName){

        return ResultJson.success(registerService.call(num,realName));
    }
    @PostMapping("/jiezhen")
    ResultJson<Register> call(Integer id){
        return ResultJson.success(registerService.jiezhen(id));
    }
    @GetMapping("/getById")
    ResultJson<Register> getById(Integer id) {
        return ResultJson.success(registerService.getById(id));
    }
}
